home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / Marlais 0.5.9-portable sources / object.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  35.4 KB  |  1,106 lines  |  [TEXT/ttxt]

  1. /*
  2.  
  3.    object.h
  4.  
  5.    This software is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License as published by the Free Software Foundation; either
  8.    version 2 of the License, or (at your option) any later version.
  9.  
  10.    This software is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public
  16.    License along with this software; if not, write to the Free
  17.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.    Original copyright notice follows:
  20.  
  21.    Copyright, 1993, Brent Benson.  All Rights Reserved.
  22.    0.4 & 0.5 Revisions Copyright 1994, Joseph N. Wilson.  All Rights Reserved.
  23.  
  24.    Permission to use, copy, and modify this software and its
  25.    documentation is hereby granted only under the following terms and
  26.    conditions.  Both the above copyright notice and this permission
  27.    notice must appear in all copies of the software, derivative works
  28.    or modified version, and both notices must appear in supporting
  29.    documentation.  Users of this software agree to the terms and
  30.    conditions set forth in this notice.
  31.  
  32.  */
  33.  
  34. #ifndef OBJECT_H
  35. #define OBJECT_H
  36.  
  37. #include <stdlib.h>
  38. #include <stdio.h>
  39. #include <stdarg.h>
  40. #include <setjmp.h>
  41.  
  42. enum objtype {
  43.     /* booleans */
  44.     True, False,
  45.  
  46.     /* numbers */
  47. #ifdef BIG_INTEGERS
  48.     Integer, BigInteger, Ratio, SingleFloat, DoubleFloat,
  49. #else
  50.     Integer, Ratio, SingleFloat, DoubleFloat,
  51. #endif
  52.  
  53.     /* collections */
  54.     EmptyList, Pair, ByteString, SimpleObjectVector,
  55.     ObjectTable, Deque, Array,
  56.  
  57.     /* conditions */
  58.     Condition,
  59.  
  60.     /* keywords and symbols */
  61.     Symbol, Keyword,
  62.  
  63.     /* characters */
  64.     Character,
  65.  
  66.     /* types */
  67.     Class, Instance, Singleton, LimitedIntType, UnionType, SlotDescriptor,
  68.  
  69.     /* functions */
  70.     Primitive, GenericFunction, Method, Function, NextMethod,
  71.  
  72.     /* misc */
  73.     EndOfFile, Values, Unspecified, Exit, Unwind, Stream,
  74.     TableEntry, UninitializedSlotValue, DequeEntry,
  75.     ForeignPtr,            /* <pcb> */
  76.     Environment
  77. };
  78.  
  79. #ifndef SMALL_OBJECTS
  80.  
  81. typedef struct object *Object;
  82.  
  83. #define TRUEP(obj)        ((obj)->type == True)
  84. #define FALSEP(obj)       ((obj)->type == False)
  85.  
  86. struct integer {
  87.     int val;
  88. };
  89.  
  90. #define INTVAL(obj)       ((obj)->u.integer.val)
  91. #define INTEGERP(obj)     ((obj)->type == Integer)
  92.  
  93. #ifdef BIG_INTEGERS
  94. struct big_integer {
  95.     void *val;
  96. };
  97.  
  98. #define BIGINTVAL(obj)    ((obj)->u.big_integer.val)
  99. #define BIGINTP(obj)      ((obj)->type == BigInteger)
  100. #define BIGINTTYPE(obj)   ((obj)->type)
  101. #endif
  102.  
  103. struct ratio {
  104.     int numerator, denominator;
  105. };
  106.  
  107. #define RATIOTYPE(obj)    ((obj)->type)
  108. #define RATIONUM(obj)     ((obj)->u.ratio.numerator)
  109. #define RATIODEN(obj)     ((obj)->u.ratio.denominator)
  110. #define RATIOP(obj)       ((obj)-type == Ratio)
  111.  
  112. struct single_float {
  113.     float val;
  114. };
  115.  
  116. #define SFLOATVAL(obj)    ((obj)->u.single_float.val)
  117. #define SFLOATP(obj)      ((obj)->type == SingleFloat)
  118.  
  119. struct double_float {
  120.     double val;
  121. };
  122.  
  123. #define DFLOATVAL(obj)    ((obj)->u.double_float.val)
  124. #define DFLOATP(obj)      ((obj)->type == DoubleFloat)
  125. #define DFLOATTYPE(obj)   ((obj)->type)
  126.  
  127. #define EMPTYLISTP(obj)   ((obj)->type == EmptyList)
  128. #define NULLP(obj)        ((obj)->type == EmptyList)
  129.  
  130. struct pair {
  131.     Object car, cdr;
  132. };
  133.  
  134. #define CAR(obj)          ((obj)->u.pair.car)
  135. #define CDR(obj)          ((obj)->u.pair.cdr)
  136. #define PAIRP(obj)        ((obj)->type == Pair)
  137. #define PAIRTYPE(obj)     ((obj)->type)
  138.  
  139. struct byte_string {
  140.     int size;
  141.     char *val;
  142. };
  143.  
  144. #define BYTESTRSIZE(obj)  ((obj)->u.byte_string.size)
  145. #define BYTESTRVAL(obj)   ((obj)->u.byte_string.val)
  146. #define BYTESTRP(obj)     ((obj)->type == ByteString)
  147. #define BYTESTRTYPE(obj)  ((obj)->type)
  148.  
  149. struct simple_object_vector {
  150.     int size;
  151.     Object *els;
  152. };
  153.  
  154. #define SOVSIZE(obj)      ((obj)->u.simple_object_vector.size)
  155. #define SOVELS(obj)       ((obj)->u.simple_object_vector.els)
  156. #define SOVP(obj)         ((obj)->type == SimpleObjectVector)
  157. #define SOVTYPE(obj)      ((obj)->type)
  158.  
  159. struct table_entry {
  160.     int row;
  161.     Object key;
  162.     Object value;
  163.     Object next;
  164. };
  165.  
  166. #define TEROW(obj)        ((obj)->u.table_entry.row)
  167. #define TEKEY(obj)        ((obj)->u.table_entry.key)
  168. #define TEVALUE(obj)      ((obj)->u.table_entry.value)
  169. #define TENEXT(obj)       ((obj)->u.table_entry.next)
  170. #define TEP(obj)          ((obj)->type == TableEntry)
  171. #define TETYPE(obj)       ((obj)->type)
  172.  
  173. struct table {
  174.     int size;
  175.     Object *the_table;
  176. };
  177.  
  178. #define TABLESIZE(obj)    ((obj)->u.table.size)
  179. #define TABLETABLE(obj)   ((obj)->u.table.the_table)
  180. #define TABLEP(obj)       ((obj)->type == ObjectTable)
  181. #define TABLETYPE(obj)    ((obj)->type)
  182.  
  183. struct deque_entry {
  184.     Object value;
  185.     Object prev, next;
  186. };
  187.  
  188. #define DEVALUE(obj)      ((obj)->u.deque_entry.value)
  189. #define DEPREV(obj)       ((obj)->u.deque_entry.prev)
  190. #define DENEXT(obj)       ((obj)->u.deque_entry.next)
  191. #define DEP(obj)          ((obj)->type == DequeEntry)
  192. #define DETYPE(obj)       ((obj)->type)
  193.  
  194. struct deque {
  195.     Object first, last;
  196. };
  197.  
  198. #define DEQUEFIRST(obj)   ((obj)->u.deque.first)
  199. #define DEQUELAST(obj)    ((obj)->u.deque.last)
  200. #define DEQUEP(obj)       ((obj)->type == Deque)
  201. #define DEQUETYPE(obj)    ((obj)->type)
  202.  
  203. struct array {
  204.     Object dimensions;
  205.     Object *elements;
  206. };
  207.  
  208. #define ARRDIMS(obj)      ((obj)->u.array.dimensions)
  209. #define ARRELS(obj)       ((obj)->u.array.elements)
  210. #define ARRAYP(obj)       ((obj)->type == Array)
  211. #define ARRTYPE(obj)      ((obj)->type)
  212.  
  213. enum condtype {
  214.     SimpleError, TypeError, SimpleWarning,
  215.     SimpleRestart, Abort
  216. };
  217. struct condition {
  218.     enum condtype type;
  219. };
  220.  
  221. #define CONDCTYPE(obj)     ((obj)->u.condition.type)
  222. #define CONDP(obj)         ((obj)->type == Condition)
  223. #define CONDTYPE(obj)      ((obj)->type)
  224.  
  225. struct symbol {
  226.     char *name;
  227. };
  228.  
  229. #define SYMBOLNAME(obj)   ((obj)->u.symbol.name)
  230. #define SYMBOLP(obj)      ((obj)->type == Symbol)
  231. #define SYMBOLTYPE(obj)   ((obj)->type)
  232. #define KEYNAME(obj)      ((obj)->u.symbol.name)
  233. #define KEYWORDP(obj)     ((obj)->type == Keyword)
  234.  
  235. struct character {
  236.     char val;
  237. };
  238.  
  239. #define CHARVAL(obj)      ((obj)->u.character.val)
  240. #define CHARP(obj)        ((obj)->type == Character)
  241.  
  242. struct slot_descriptor {
  243.     unsigned char properties;
  244.     Object getter;
  245.     Object setter;
  246.     Object slot_type;
  247.     Object init;
  248.     Object init_keyword;
  249.     Object allocation;
  250.     Object dynamism;
  251. };
  252.  
  253. #define SLOTDPROPS(obj)         ((obj)->u.slot_descriptor.properties)
  254. #define SLOTDKEYREQMASK         0x01
  255. #define SLOTDINHERITEDMASK      0x02
  256. #define SLOTDINITFUNCTIONMASK   0x04
  257. #define SLOTDDEFERREDTYPEMASK    0x08
  258. #define SLOTDKEYREQ(obj)        (SLOTDPROPS (obj) & SLOTDKEYREQMASK)
  259. #define SLOTDINHERITED(obj)     (SLOTDPROPS (obj) & SLOTDINHERITEDMASK)
  260. #define SLOTDINITFUNCTION(obj)  (SLOTDPROPS (obj) & SLOTDINITFUNCTIONMASK)
  261. #define SLOTDDEFERREDTYPE(obj)  (SLOTDPROPS (obj) & SLOTDDEFERREDTYPEMASK)
  262. #define SLOTDGETTER(obj)        ((obj)->u.slot_descriptor.getter)
  263. #define SLOTDSETTER(obj)        ((obj)->u.slot_descriptor.setter)
  264. #define SLOTDSLOTTYPE(obj)      ((obj)->u.slot_descriptor.slot_type)
  265. #define SLOTDINIT(obj)          ((obj)->u.slot_descriptor.init)
  266. #define SLOTDINITKEYWORD(obj)   ((obj)->u.slot_descriptor.init_keyword)
  267. #define SLOTDALLOCATION(obj)    ((obj)->u.slot_descriptor.allocation)
  268. #define SLOTDDYNAMISM(obj)      ((obj)->u.slot_descriptor.dynamism)
  269. #define SLOTDP(obj)             ((obj)->type == SlotDescriptor)
  270. #define SLOTDTYPE(obj)          ((obj)->type)
  271.  
  272. struct class {
  273.     Object name;
  274.     Object supers;
  275.     Object subs;
  276.     Object inherited_slot_descriptors;
  277.     Object inst_slot_descriptors;
  278.     Object class_slot_descriptors;
  279.     Object class_slots;
  280.     Object eachsubclass_slot_descriptors;
  281.     Object eachsubclass_slots;
  282.     Object constant_slot_descriptors;
  283.     Object virtual_slot_descriptors;
  284.     Object precedence_list;
  285.     int properties;
  286.     struct frame *creation_env;
  287. };
  288.  
  289. #define CLASSNAME(obj)     ((obj)->u.class.name)
  290. #define CLASSSUPERS(obj)   ((obj)->u.class.supers)
  291. #define CLASSSUBS(obj)     ((obj)->u.class.subs)
  292. #define CLASSSLOTDS(obj)   ((obj)->u.class.inst_slot_descriptors)
  293. #define CLASSINSLOTDS(obj) ((obj)->u.class.inherited_slot_descriptors)
  294. #define CLASSCSLOTDS(obj)  ((obj)->u.class.class_slot_descriptors)
  295. #define CLASSCSLOTS(obj)   ((obj)->u.class.class_slots)
  296. #define CLASSESSLOTDS(obj) ((obj)->u.class.eachsubclass_slot_descriptors)
  297. #define CLASSESSLOTS(obj)  ((obj)->u.class.eachsubclass_slots)
  298. #define CLASSCONSTSLOTDS(obj) ((obj)->u.class.constant_slot_descriptors)
  299. #define CLASSVSLOTDS(obj)  ((obj)->u.class.virtual_slot_descriptors)
  300. #define CLASSPRECLIST(obj) ((obj)->u.class.precedence_list)
  301. #define CLASSP(obj)        ((obj)->type == Class)
  302. #define CLASSTYPE(obj)     ((obj)->type)
  303. #define CLASSPROPS(obj)    ((obj)->u.class.properties)
  304. #define CLASSSEAL          0x01
  305. #define SEALEDP(obj)       (CLASSP (obj) && (CLASSPROPS (obj) & CLASSSEAL))
  306. #define CLASSINSTANTIABLE  0x02
  307. #define INSTANTIABLE(obj)  (CLASSP (obj) && (CLASSPROPS (obj) & CLASSINSTANTIABLE))
  308. #define CLASSSLOTSUNINIT   0x04
  309. #define CLASSUNINITIALIZED(obj)  (CLASSP (obj) && (CLASSPROPS (obj) & CLASSSLOTSUNINIT))
  310. #define CLASSENV(obj)      ((obj)->u.class.creation_env);
  311.  
  312. struct instance {
  313.     Object class;
  314.     Object *slots;
  315. };
  316.  
  317. #define INSTCLASS(obj)    ((obj)->u.instance.class)
  318. #define INSTSLOTS(obj)    ((obj)->u.instance.slots)
  319. #define INSTANCEP(obj)    ((obj)->type == Instance)
  320. #define INSTTYPE(obj)     ((obj)->type)
  321.  
  322. struct singleton {
  323.     Object val;
  324. };
  325.  
  326. #define SINGLEVAL(obj)    ((obj)->u.singleton.val)
  327. #define SINGLETONP(obj)   ((obj)->type == Singleton)
  328. #define SINGLETYPE(obj)   ((obj)->type)
  329.  
  330. struct limited_int_type {
  331.     unsigned char properties;
  332.     int min, max;
  333. };
  334.  
  335. #define LIMINTPROPS(obj)  ((obj)->u.limited_int_type.properties)
  336. #define LIMMINMASK 0x01
  337. #define LIMINTHASMIN(obj) (LIMINTPROPS (obj) & LIMMINMASK)
  338. #define LIMMAXMASK 0x02
  339. #define LIMINTHASMAX(obj) (LIMINTPROPS (obj) & LIMMAXMASK)
  340. #define LIMINTMIN(obj)    ((obj)->u.limited_int_type.min)
  341. #define LIMINTMAX(obj)    ((obj)->u.limited_int_type.max)
  342. #define LIMINTP(obj)      ((obj)->type == LimitedIntType)
  343. #define LIMINTTYPE(obj)   ((obj)->type)
  344.  
  345. struct union_type {
  346.     Object list;
  347. };
  348.  
  349. #define UNIONP(obj)       ((obj)->type == UnionType)
  350. #define UNIONTYPE(obj)    ((obj)->type)
  351. #define UNIONLIST(obj)    ((obj)->u.union_type.list)
  352.  
  353. enum primtype {
  354.     /* prim_n: n required  */
  355.     /* prim_n_m: n requied, m optional */
  356.     /* prim_n_rest: n required, rest args */
  357.     prim_0, prim_1, prim_2, prim_3,
  358.     prim_0_1, prim_0_2, prim_0_3,
  359.     prim_1_1, prim_1_2, prim_2_1,
  360.     prim_0_rest, prim_1_rest, prim_2_rest
  361. };
  362.  
  363. struct primitive {
  364.     char *name;
  365.     enum primtype prim_type;
  366.     Object (*fun) ();
  367. };
  368.  
  369. #define PRIMNAME(obj)     ((obj)->u.primitive.name)
  370. #define PRIMPTYPE(obj)    ((obj)->u.primitive.prim_type)
  371. #define PRIMFUN(obj)      ((obj)->u.primitive.fun)
  372. #define PRIMP(obj)        ((obj)->type == Primitive)
  373. #define PRIMTYPE(obj)     ((obj)->type)
  374.  
  375. struct generic_function {
  376.     Object name;
  377.     unsigned char properties;
  378.     Object required_params;
  379.     Object key_params;
  380.     Object rest_param;
  381.     Object required_return_types;
  382.     Object rest_return_type;
  383.     Object methods;
  384. };
  385.  
  386. #define GFNAME(obj)       ((obj)->u.generic_function.name)
  387. #define GFPROPS(obj)      ((obj)->u.generic_function.properties)
  388. #define GFALLKEYSMASK     0x01
  389. #define GFKEYSMASK        0x02
  390. #define GFHASKEYS(obj)    (GFPROPS(obj) & GFKEYSMASK)
  391. #define GFALLKEYS(obj)    (GFPROPS(obj) & GFALLKEYSMASK)
  392. #define GFREQPARAMS(obj)  ((obj)->u.generic_function.required_params)
  393. #define GFKEYPARAMS(obj)  ((obj)->u.generic_function.key_params)
  394. #define GFRESTPARAM(obj)  ((obj)->u.generic_function.rest_param)
  395. #define GFREQVALUES(obj)  ((obj)->u.generic_function.required_return_types)
  396. #define GFRESTVALUES(obj) ((obj)->u.generic_function.rest_return_type)
  397. #define GFMETHODS(obj)    ((obj)->u.generic_function.methods)
  398. #define GFUNP(obj)        ((obj)->type == GenericFunction)
  399. #define GFTYPE(obj)       ((obj)->type)
  400.  
  401. struct method {
  402.     Object name;
  403.     unsigned char properties;
  404.     Object required_params;
  405.     Object next_method;
  406.     Object key_params;
  407.     Object rest_param;
  408.     Object required_return_types;
  409.     Object rest_return_type;
  410.     Object body;
  411.     struct frame *env;
  412. };
  413.  
  414. #define METHNAME(obj)       ((obj)->u.method.name)
  415. #define METHPROPS(obj)      ((obj)->u.method.properties)
  416. #define METHALLKEYSMASK     0x01
  417. #define METHALLKEYS(obj)    (METHPROPS(obj) & METHALLKEYSMASK)
  418. #define METHREQPARAMS(obj)  ((obj)->u.method.required_params)
  419. #define METHNEXTMETH(obj)   ((obj)->u.method.next_method)
  420. #define METHKEYPARAMS(obj)  ((obj)->u.method.key_params)
  421. #define METHRESTPARAM(obj)  ((obj)->u.method.rest_param)
  422. #define METHREQVALUES(obj)  ((obj)->u.method.required_return_types)
  423. #define METHRESTVALUES(obj) ((obj)->u.method.rest_return_type)
  424. #define METHBODY(obj)       ((obj)->u.method.body)
  425. #define METHENV(obj)        ((obj)->u.method.env)
  426. #define METHODP(obj)        ((obj)->type == Method)
  427. #define METHTYPE(obj)       ((obj)->type)
  428.  
  429. struct next_method {
  430.     Object rest_methods;
  431.     Object args;
  432. };
  433.  
  434. #define NMREST(obj)       ((obj)->u.next_method.rest_methods)
  435. #define NMARGS(obj)       ((obj)->u.next_method.args)
  436. #define NMETHP(obj)       ((obj)->type == NextMethod)
  437. #define NMTYPE(obj)       ((obj)->type)
  438.  
  439. #define EOFP(obj)         ((obj)->type == EndOfFile)
  440.  
  441. struct values {
  442.     int num;
  443.     Object *els;
  444. };
  445.  
  446. #define VALUESNUM(obj)    ((obj)->u.values.num)
  447. #define VALUESELS(obj)    ((obj)->u.values.els)
  448. #define VALUESP(obj)      ((obj)->type == Values)
  449. #define VALUESTYPE(obj)   ((obj)->type)
  450.  
  451. #define UNSPECIFIEDP(obj) ((obj)->type == Unspecified)
  452.  
  453. struct exitproc {
  454.     Object sym;
  455.     jmp_buf *ret;
  456. };
  457.  
  458. #define EXITSYM(obj)      ((obj)->u.exitproc.sym)
  459. #define EXITRET(obj)      ((obj)->u.exitproc.ret)
  460. #define EXITP(obj)        ((obj)->type == Exit)
  461. #define EXITTYPE(obj)     ((obj)->type)
  462.  
  463. struct unwind {
  464.     Object body;
  465. };
  466.  
  467. #define UNWINDBODY(obj)   ((obj)->u.unwind.body)
  468. #define UNWINDP(obj)      ((obj)->type == Unwind)
  469. #define UNWINDTYPE(obj)   ((obj)->type)
  470.  
  471. enum streamtype {
  472.     Input, Output
  473. };
  474. struct stream {
  475.     enum streamtype stream_type;
  476.     FILE *fp;
  477. };
  478.  
  479. #define STREAMSTYPE(obj)   ((obj)->u.stream.stream_type)
  480. #define STREAMFP(obj)      ((obj)->u.stream.fp)
  481. #define STREAMP(obj)       ((obj)->type == Stream)
  482. #define STREAMTYPE(obj)    ((obj)->type)
  483. #define INPUTSTREAMP(obj)  (STREAMP(obj) && (STREAMSTYPE(obj) == Input))
  484. #define OUTPUTSTREAMP(obj) (STREAMP(obj) && (STREAMSTYPE(obj) == Output))
  485.  
  486. #define UNINITSLOTP(obj)   ((obj)->type == UninitializedSlotValue)
  487.  
  488. /* <pcb> a wrapper around a system pointer. */
  489.  
  490. struct foreign_ptr {
  491.     void *ptr;
  492. };
  493.  
  494. #define FOREIGNPTR(obj)      ((obj)->u.ptr)
  495. #define FOREIGNP(obj)        (POINTERP(obj) && (POINTERTYPE(obj) == ForeignPtr))
  496. #define FOREIGNTYPE(obj)     ((obj)->type)
  497.  
  498. struct environment {
  499.     struct frame *env;
  500. };
  501.  
  502. #define ENVIRONMENT(obj)      ((obj)->u.env)
  503. #define ENVIRONMENTP(obj)        (POINTERP(obj) && (POINTERTYPE(obj) == Environment))
  504. #define ENVIRONMENTTYPE(obj)     ((obj)->type)
  505.  
  506. struct object {
  507.     enum objtype type;
  508.     union {
  509.     struct integer integer;
  510. #ifdef BIG_INTEGERS
  511.     struct big_integer big_integer;        /* <pcb> */
  512. #endif
  513.     struct ratio ratio;
  514.     struct single_float single_float;
  515.     struct double_float double_float;
  516.     struct pair pair;
  517.     struct byte_string byte_string;
  518.     struct simple_object_vector simple_object_vector;
  519.     struct table table;
  520.     struct deque deque;
  521.     struct array array;
  522.     struct condition condition;
  523.     struct symbol symbol;
  524.     struct character character;
  525.     struct class class;
  526.     struct instance instance;
  527.     struct singleton singleton;
  528.     struct limited_int_type limited_int_type;
  529.     struct union_type union_type;
  530.     struct slot_descriptor slot_descriptor;
  531.     struct primitive primitive;
  532.     struct generic_function generic_function;
  533.     struct method method;
  534.     struct next_method next_method;
  535.     struct values values;
  536.     struct exitproc exitproc;
  537.     struct unwind unwind;
  538.     struct stream stream;
  539.     struct table_entry table_entry;
  540.     struct deque_entry deque_entry;
  541.     struct foreign_ptr foreign_ptr;
  542.     } u;
  543. };
  544.  
  545. #define TYPE(obj)        ((obj)->type)
  546. #define POINTERTYPE(obj) ((obj)->type)
  547. #define LISTP(obj)       (NULLP(obj) || PAIRP(obj))
  548. #define POINTERP(obj)    (1)
  549.  
  550. #else /* SMALL_OBJECTS */
  551.  
  552. /*
  553.    Data Representation:
  554.  
  555.    pointer:   PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP00  (P=pointer address bit)
  556.    immed:     DDDDDDDDDDDDDDDDDDDDDDDDDDSSSS01  (D=immediate data, S=secondary tag)
  557.    integer:   IIIIIIIIIIIIIIIIIIIIIIIIIIIIII10  (I=immediate integer data)
  558.  
  559.  */
  560.  
  561. typedef void *Object;
  562.  
  563. #define POINTERTAG           0
  564. #define IMMEDTAG             1
  565. #define INTEGERTAG           2
  566.  
  567. #define POINTERP(obj)        (((unsigned)obj & 3) == POINTERTAG)
  568. #define IMMEDP(obj)          (((unsigned)obj & 3) == IMMEDTAG)
  569. #define INTEGERP(obj)        (((unsigned)obj & 3) == INTEGERTAG)
  570.  
  571. /* macros for identifying immediates other than integers
  572.  */
  573. #define SUBPART(obj)         (((unsigned)obj & 0x3c) >> 2)
  574.  
  575. #define TRUESUB    0x00
  576. #define FALSESUB   0x01
  577. #define EMPTYSUB   0x02
  578. #define CHARSUB    0x03
  579. #define EOFSUB     0x04
  580. #define UNSPECSUB  0x05
  581. #define UNINITSUB  0x06
  582. /* add more immediate types here */
  583.  
  584. #define TRUEP(obj)          (IMMEDP(obj) && (SUBPART(obj) == TRUESUB))
  585. #define FALSEP(obj)         (IMMEDP(obj) && (SUBPART(obj) == FALSESUB))
  586. #define EMPTYLISTP(obj)     (IMMEDP(obj) && (SUBPART(obj) == EMPTYSUB))
  587. #define CHARP(obj)          (IMMEDP(obj) && (SUBPART(obj) == CHARSUB))
  588. #define EOFP(obj)           (IMMEDP(obj) && (SUBPART(obj) == EOFSUB))
  589. #define UNSPECP(obj)        (IMMEDP(obj) && (SUBPART(obj) == UNSPECSUB))
  590. #define UNINITSLOTP(obj)    (IMMEDP(obj) && (SUBPART(obj) == UNINITSUB))
  591.  
  592. /* actual values of constant immediates
  593.  */
  594. #define TRUEVAL         ((Object)((TRUESUB << 2)   | IMMEDTAG))
  595. #define FALSEVAL        ((Object)((FALSESUB << 2)  | IMMEDTAG))
  596. #define EMPTYLISTVAL    ((Object)((EMPTYSUB << 2)  | IMMEDTAG))
  597. #define EOFVAL          ((Object)((EOFSUB << 2)    | IMMEDTAG))
  598. #define UNSPECVAL       ((Object)((UNSPECSUB << 2) | IMMEDTAG))
  599. #define UNINITVAL       ((Object)((UNINITSUB << 2) | IMMEDTAG))
  600.  
  601. /* macros for extracting relevant parts of object
  602.  */
  603. #define POINTER_PART(obj)    (obj)
  604. #define IMMED_PART(obj)      ((unsigned)obj >> 6)
  605. #define INTEGER_PART(obj)    ((int)obj >> 2)
  606. #define INTVAL(obj)          ((int)obj >> 2)
  607. #define CHARVAL(obj)         ((unsigned)obj >> 6)
  608.  
  609. /* macros for synthesizing immediates
  610.  */
  611. #define MAKE_CHAR(ch)        ((Object)(((unsigned)ch << 6) | (CHARSUB << 2) | IMMEDTAG))
  612. #define MAKE_INT(i)          ((Object)((i << 2) | INTEGERTAG))
  613.  
  614. #ifdef BIG_INTEGERS
  615. /* BigInteger support. <pcb> */
  616.  
  617. struct big_integer {
  618.     enum objtype type;
  619.     void *val;
  620. };
  621.  
  622. #define BIGINTVAL(obj)    (((struct big_integer *)obj)->val)
  623. #define BIGINTP(obj)      (((struct big_integer *)obj)->type == BigInteger)
  624. #define BIGINTTYPE(obj)   (((struct big_integer *)obj)->type)
  625. #endif
  626.  
  627. struct ratio {
  628.     enum objtype type;
  629.     int numerator, denominator;
  630. };
  631.  
  632. #define RATIOTYPE(obj)    (((struct ratio *)obj)->type)
  633. #define RATIONUM(obj)     (((struct ratio *)obj)->numerator)
  634. #define RATIODEN(obj)     (((struct ratio *)obj)->denominator)
  635. #define RATIOP(obj)       (POINTERP(obj) && (RATIOTYPE(obj) == Ratio))
  636.  
  637. struct double_float {
  638.     enum objtype type;
  639.     double val;
  640. };
  641.  
  642. #define DFLOATTYPE(obj)   (((struct double_float *)obj)->type)
  643. #define DFLOATVAL(obj)    (((struct double_float *)obj)->val)
  644. #define DFLOATP(obj)      (POINTERP(obj) && (DFLOATTYPE(obj) == DoubleFloat))
  645.  
  646. struct pair {
  647.     enum objtype type;
  648.     Object car, cdr;
  649. };
  650.  
  651. #define PAIRTYPE(obj)     (((struct pair *)obj)->type)
  652. #define CAR(obj)          (((struct pair *)obj)->car)
  653. #define CDR(obj)          (((struct pair *)obj)->cdr)
  654. #define PAIRP(obj)        (POINTERP(obj) && (PAIRTYPE(obj) == Pair))
  655.  
  656. struct byte_string {
  657.     enum objtype type;
  658.     int size;
  659.     char *val;
  660. };
  661.  
  662. #define BYTESTRTYPE(obj)  (((struct byte_string *)obj)->type)
  663. #define BYTESTRSIZE(obj)  (((struct byte_string *)obj)->size)
  664. #define BYTESTRVAL(obj)   (((struct byte_string *)obj)->val)
  665. #define BYTESTRP(obj)     (POINTERP(obj) && (BYTESTRTYPE(obj) == ByteString))
  666.  
  667. struct simple_object_vector {
  668.     enum objtype type;
  669.     int size;
  670.     Object *els;
  671. };
  672.  
  673. #define SOVTYPE(obj)      (((struct simple_object_vector *)obj)->type)
  674. #define SOVSIZE(obj)      (((struct simple_object_vector *)obj)->size)
  675. #define SOVELS(obj)       (((struct simple_object_vector *)obj)->els)
  676. #define SOVP(obj)         (POINTERP(obj) && (SOVTYPE(obj) == SimpleObjectVector))
  677.  
  678. struct table_entry {
  679.     enum objtype type;
  680.     int row;
  681.     Object key;
  682.     Object value;
  683.     Object next;
  684. };
  685.  
  686. #define TETYPE(obj)       (((struct table_entry *)obj)->type)
  687. #define TEROW(obj)        (((struct table_entry *)obj)->row)
  688. #define TEKEY(obj)        (((struct table_entry *)obj)->key)
  689. #define TEVALUE(obj)      (((struct table_entry *)obj)->value)
  690. #define TENEXT(obj)       (((struct table_entry *)obj)->next)
  691. #define TEP(obj)          (POINTERP(obj) && (TETYPE(obj) == TableEntry))
  692.  
  693. struct table {
  694.     enum objtype type;
  695.     int size;
  696.     Object *the_table;
  697. };
  698.  
  699. #define TABLETYPE(obj)    (((struct table *)obj)->type)
  700. #define TABLESIZE(obj)    (((struct table *)obj)->size)
  701. #define TABLETABLE(obj)   (((struct table *)obj)->the_table)
  702. #define TABLEP(obj)       (POINTERP(obj) && (TABLETYPE(obj) == ObjectTable))
  703.  
  704. struct deque_entry {
  705.     enum objtype type;
  706.     Object value;
  707.     Object prev, next;
  708. };
  709.  
  710. #define DETYPE(obj)       (((struct deque_entry *)obj)->type)
  711. #define DEVALUE(obj)      (((struct deque_entry *)obj)->value)
  712. #define DEPREV(obj)       (((struct deque_entry *)obj)->prev)
  713. #define DENEXT(obj)       (((struct deque_entry *)obj)->next)
  714. #define DEP(obj)          (POINTERP(obj) && (DETYPE(obj) == Deque))
  715.  
  716. struct deque {
  717.     enum objtype type;
  718.     Object first, last;
  719. };
  720.  
  721. #define DEQUETYPE(obj)    (((struct deque *)obj)->type)
  722. #define DEQUEFIRST(obj)   (((struct deque *)obj)->first)
  723. #define DEQUELAST(obj)    (((struct deque *)obj)->last)
  724. #define DEQUEP(obj)       (POINTERP(obj) && (DEQUETYPE(obj) == Deque))
  725.  
  726. struct array {
  727.     enum objtype type;
  728.     Object dimensions;
  729.     Object *elements;
  730. };
  731.  
  732. #define ARRTYPE(obj)      (((struct array *)obj)->type)
  733. #define ARRDIMS(obj)      (((struct array *)obj)->dimensions)
  734. #define ARRELS(obj)       (((struct array *)obj)->elements)
  735. #define ARRAYP(obj)       (POINTERP(obj) && (ARRTYPE(obj) == Array))
  736.  
  737. enum condtype {
  738.     SimpleError, TypeError, SimpleWarning,
  739.     SimpleRestart, Abort
  740. };
  741. struct condition {
  742.     enum objtype type;
  743.     enum condtype condtype;
  744. };
  745.  
  746. #define CONDTYPE(obj)     (((struct condition *)obj)->type)
  747. #define CONDCTYPE(obj)    (((struct condition *)obj)->condtype)
  748. #define CONDP(obj)        (POINTERP(obj) && (CONDTYPE(obj) == Condition))
  749.  
  750. struct symbol {
  751.     enum objtype type;
  752.     char *name;
  753. };
  754.  
  755. #define SYMBOLTYPE(obj)   (((struct symbol *)obj)->type)
  756. #define SYMBOLNAME(obj)   (((struct symbol *)obj)->name)
  757. #define SYMBOLP(obj)      (POINTERP(obj) && (SYMBOLTYPE(obj) == Symbol))
  758. #define KEYNAME(obj)      (((struct symbol *)obj)->name)
  759. #define KEYWORDP(obj)     (POINTERP(obj) && (SYMBOLTYPE(obj) == Keyword))
  760.  
  761. struct slot_descriptor {
  762.     enum objtype type;
  763.     unsigned char properties;
  764.     Object getter_name;
  765.     Object setter_name;
  766.     Object slot_type;
  767.     Object init;
  768.     Object init_keyword;
  769.     Object allocation;
  770.     Object dynamism;
  771. };
  772.  
  773. #define SLOTDPROPS(obj)        (((struct slot_descriptor *)obj)->properties)
  774. #define SLOTDKEYREQMASK        0x01
  775. #define SLOTDINHERITEDMASK     0x02
  776. #define SLOTDINITFUNCTIONMASK  0x04
  777. #define SLOTDDEFERREDTYPEMASK  0x08
  778. #define SLOTDKEYREQ(obj)       (SLOTDPROPS (obj) & SLOTDKEYREQMASK)
  779. #define SLOTDINHERITED(obj)    (SLOTDPROPS (obj) & SLOTDINHERITEDMASK)
  780. #define SLOTDINITFUNCTION(obj) (SLOTDPROPS (obj) & SLOTDINITFUNCTIONMASK)
  781. #define SLOTDDEFERREDTYPE(obj) (SLOTDPROPS (obj) & SLOTDDEFERREDTYPEMASK)
  782. #define SLOTDGETTER(obj)       (((struct slot_descriptor *)obj)->getter_name)
  783. #define SLOTDSETTER(obj)       (((struct slot_descriptor *)obj)->setter_name)
  784. #define SLOTDSLOTTYPE(obj)     (((struct slot_descriptor *)obj)->slot_type)
  785. #define SLOTDINIT(obj)         (((struct slot_descriptor *)obj)->init)
  786. #define SLOTDINITKEYWORD(obj)  (((struct slot_descriptor *)obj)->init_keyword)
  787. #define SLOTDALLOCATION(obj)   (((struct slot_descriptor *)obj)->allocation)
  788. #define SLOTDDYNAMISM(obj)     (((struct slot_descriptor *)obj)->dynamism)
  789. #define SLOTDP(obj)            (POINTERP(obj) && (CLASSTYPE(obj) == SlotDescriptor))
  790. #define SLOTDTYPE(obj)         (((struct slot_descriptor *)obj)->type)
  791.  
  792. struct class {
  793.     enum objtype type;
  794.     Object name;
  795.     Object supers;
  796.     Object subs;
  797.     Object inherited_slot_descriptors;
  798.     Object inst_slot_descriptors;
  799.     Object class_slot_descriptors;
  800.     Object class_slots;
  801.     Object eachsubclass_slot_descriptors;
  802.     Object eachsubclass_slots;
  803.     Object constant_slot_descriptors;
  804.     Object virtual_slot_descriptors;
  805.     Object precedence_list;
  806.     int properties;
  807.     struct frame *creation_env;
  808. };
  809.  
  810. #define CLASSTYPE(obj)    (((struct class *)obj)->type)
  811. #define CLASSNAME(obj)    (((struct class *)obj)->name)
  812. #define CLASSSUPERS(obj)  (((struct class *)obj)->supers)
  813. #define CLASSSUBS(obj)    (((struct class *)obj)->subs)
  814. #define CLASSINSLOTDS(obj) (((struct class *)obj)->inherited_slot_descriptors)
  815. #define CLASSSLOTDS(obj)  (((struct class *)obj)->inst_slot_descriptors)
  816. #define CLASSCSLOTS(obj)  (((struct class *)obj)->class_slots)
  817. #define CLASSCSLOTDS(obj) (((struct class *)obj)->class_slot_descriptors)
  818. #define CLASSESSLOTDS(obj) (((struct class *)obj)->eachsubclass_slot_descriptors)
  819. #define CLASSESSLOTS(obj) (((struct class *)obj)->eachsubclass_slots)
  820. #define CLASSCONSTSLOTDS(obj) (((struct class *)obj)->constant_slot_descriptors)
  821. #define CLASSVSLOTDS(obj) (((struct class *)obj)->virtual_slot_descriptors)
  822. #define CLASSPRECLIST(obj)(((struct class *)obj)->precedence_list)
  823. #define CLASSP(obj)       (POINTERP(obj) && (CLASSTYPE(obj) == Class))
  824. #define CLASSPROPS(obj)   (((struct class *)obj)->properties)
  825. #define CLASSSEAL         0x01
  826. #define SEALEDP(obj)      (CLASSP (obj) && (CLASSPROPS (obj) & CLASSSEAL))
  827. #define CLASSINSTANTIABLE 0x02
  828. #define INSTANTIABLE(obj) (CLASSP (obj) && (CLASSPROPS (obj) & CLASSINSTANTIABLE))
  829. #define CLASSSLOTSUNINIT   0x04
  830. #define CLASSUNINITIALIZED(obj)  (CLASSP (obj) && (CLASSPROPS (obj) & CLASSSLOTSUNINIT))
  831. #define CLASSENV(obj)     (((struct class *)obj)->creation_env)
  832.  
  833. struct instance {
  834.     enum objtype type;
  835.     Object class;
  836.     Object *slots;
  837. };
  838.  
  839. #define INSTTYPE(obj)     (((struct instance *)obj)->type)
  840. #define INSTCLASS(obj)    (((struct instance *)obj)->class)
  841. #define INSTSLOTS(obj)    (((struct instance *)obj)->slots)
  842. #define INSTANCEP(obj)    (POINTERP(obj) && (INSTTYPE(obj) == Instance))
  843.  
  844. struct singleton {
  845.     enum objtype type;
  846.     Object val;
  847. };
  848.  
  849. #define SINGLETYPE(obj)   (((struct singleton *)obj)->type)
  850. #define SINGLEVAL(obj)    (((struct singleton *)obj)->val)
  851. #define SINGLETONP(obj)   (POINTERP(obj) && (SINGLETYPE(obj) == Singleton))
  852.  
  853.  
  854. struct limited_int_type {
  855.     enum objtype type;
  856.     unsigned char properties;
  857.     int min, max;
  858. };
  859.  
  860. #define LIMINTPROPS(obj)  (((struct limited_int_type *)obj)->properties)
  861. #define LIMMINMASK 0x01
  862. #define LIMINTHASMIN(obj) (LIMINTPROPS (obj) & LIMMINMASK)
  863. #define LIMMAXMASK 0x02
  864. #define LIMINTHASMAX(obj) (LIMINTPROPS (obj) & LIMMAXMASK)
  865. #define LIMINTMIN(obj)    (((struct limited_int_type *)obj)->min)
  866. #define LIMINTMAX(obj)    (((struct limited_int_type *)obj)->max)
  867. #define LIMINTP(obj)      (POINTERP(obj) && (LIMINTTYPE(obj) == LimitedIntType))
  868. #define LIMINTTYPE(obj)   (((struct limited_int_type *)obj)->type)
  869.  
  870. struct union_type {
  871.     enum objtype type;
  872.     Object list;
  873. };
  874.  
  875. #define UNIONP(obj)       (POINTERP(obj) && (UNIONTYPE(obj) == UnionType))
  876. #define UNIONTYPE(obj)    (((struct union_type *)obj)->type)
  877. #define UNIONLIST(obj)    (((struct union_type *)obj)->list)
  878. enum primtype {
  879.     /* prim_n: n required  */
  880.     /* prim_n_m: n requied, m optional */
  881.     /* prim_n_rest: n required, rest args */
  882.     prim_0, prim_1, prim_2, prim_3,
  883.     prim_0_1, prim_0_2, prim_0_3,
  884.     prim_1_1, prim_1_2, prim_2_1,
  885.     prim_0_rest, prim_1_rest, prim_2_rest
  886. };
  887.  
  888. struct primitive {
  889.     char *name;
  890.     enum primtype prim_type;
  891.     Object (*fun) ();
  892. };
  893.  
  894. struct prim {
  895.     enum objtype type;
  896.     struct primitive p;
  897. };
  898.  
  899. #define PRIMTYPE(obj)     (((struct prim *)obj)->type)
  900. #define PRIMNAME(obj)     (((struct prim *)obj)->p.name)
  901. #define PRIMPTYPE(obj)    (((struct prim *)obj)->p.prim_type)
  902. #define PRIMFUN(obj)      (((struct prim *)obj)->p.fun)
  903. #define PRIMP(obj)        (POINTERP(obj) && (PRIMTYPE(obj) == Primitive))
  904.  
  905. struct generic_function {
  906.     enum objtype type;
  907.     Object name;
  908.     unsigned char properties;
  909.     Object required_params;
  910.     Object key_params;
  911.     Object rest_param;
  912.     Object required_return_types;
  913.     Object rest_return_type;
  914.     Object methods;
  915. };
  916.  
  917. #define GFTYPE(obj)       (((struct generic_function *)obj)->type)
  918. #define GFNAME(obj)       (((struct generic_function *)obj)->name)
  919. #define GFNAME(obj)       (((struct generic_function *)obj)->name)
  920. #define GFPROPS(obj)      (((struct generic_function *)obj)->properties)
  921. #define GFALLKEYSMASK     0x01
  922. #define GFKEYSMASK        0x02
  923. #define GFHASKEYS(obj)    (GFPROPS(obj) & GFKEYSMASK)
  924. #define GFALLKEYS(obj)    (GFPROPS(obj) & GFALLKEYSMASK)
  925. #define GFREQPARAMS(obj)  (((struct generic_function *)obj)->required_params)
  926. #define GFKEYPARAMS(obj)  (((struct generic_function *)obj)->key_params)
  927. #define GFRESTPARAM(obj)  (((struct generic_function *)obj)->rest_param)
  928. #define GFREQVALUES(obj)  (((struct generic_function *)obj)->required_return_types)
  929. #define GFRESTVALUES(obj) (((struct generic_function *)obj)->rest_return_type)
  930. #define GFMETHODS(obj)    (((struct generic_function *)obj)->methods)
  931. #define GFUNP(obj)        (POINTERP(obj) && (GFTYPE(obj) == GenericFunction))
  932.  
  933. struct method {
  934.     enum objtype type;
  935.     Object name;
  936.     unsigned char properties;
  937.     Object required_params;
  938.     Object next_method;
  939.     Object key_params;
  940.     Object rest_param;
  941.     Object required_return_types;
  942.     Object rest_return_type;
  943.     Object body;
  944.     struct frame *env;
  945. };
  946.  
  947. #define METHTYPE(obj)       (((struct method *)obj)->type)
  948. #define METHNAME(obj)       (((struct method *)obj)->name)
  949. #define METHNEXTMETH(obj)   (((struct method *)obj)->next_method)
  950. #define METHPROPS(obj)      (((struct method *)obj)->properties)
  951. #define METHALLKEYSMASK     0x01
  952. #define METHALLKEYS(obj)    (METHPROPS(obj) & METHALLKEYSMASK)
  953. #define METHREQPARAMS(obj)  (((struct method *)obj)->required_params)
  954. #define METHKEYPARAMS(obj)  (((struct method *)obj)->key_params)
  955. #define METHRESTPARAM(obj)  (((struct method *)obj)->rest_param)
  956. #define METHREQVALUES(obj)  (((struct method *)obj)->required_return_types)
  957. #define METHRESTVALUES(obj) (((struct method *)obj)->rest_return_type)
  958. #define METHBODY(obj)       (((struct method *)obj)->body)
  959. #define METHENV(obj)        (((struct method *)obj)->env)
  960. #define METHODP(obj)        (POINTERP(obj) && (METHTYPE(obj) == Method))
  961.  
  962. struct next_method {
  963.     enum objtype type;
  964.     Object rest_methods;
  965.     Object args;
  966. };
  967.  
  968. #define NMTYPE(obj)       (((struct next_method *)obj)->type)
  969. #define NMREST(obj)       (((struct next_method *)obj)->rest_methods)
  970. #define NMARGS(obj)       (((struct next_method *)obj)->args)
  971. #define NMETHP(obj)       (POINTERP(obj) && (NMTYPE(obj) == NextMethod))
  972.  
  973. struct values {
  974.     enum objtype type;
  975.     int num;
  976.     Object *els;
  977. };
  978.  
  979. #define VALUESTYPE(obj)   (((struct values *)obj)->type)
  980. #define VALUESNUM(obj)    (((struct values *)obj)->num)
  981. #define VALUESELS(obj)    (((struct values *)obj)->els)
  982. #define VALUESP(obj)      (POINTERP(obj) && (VALUESTYPE(obj) == Values))
  983.  
  984. #define UNSPECIFIEDP(obj) ((obj)->type == Unspecified)
  985.  
  986. struct exitproc {
  987.     enum objtype type;
  988.     Object sym;
  989.     jmp_buf *ret;
  990. };
  991.  
  992. #define EXITTYPE(obj)     (((struct exitproc *)obj)->type)
  993. #define EXITSYM(obj)      (((struct exitproc *)obj)->sym)
  994. #define EXITRET(obj)      (((struct exitproc *)obj)->ret)
  995. #define EXITP(obj)        (POINTERP(obj) && (EXITTYPE(obj) == Exit))
  996.  
  997. struct unwind {
  998.     enum objtype type;
  999.     Object body;
  1000. };
  1001.  
  1002. #define UNWINDTYPE(obj)   (((struct unwind *)obj)->type)
  1003. #define UNWINDBODY(obj)   (((struct unwind *)obj)->body)
  1004. #define UNWINDP(obj)      (POINTERP(obj) && (UNWINDTYPE(obj) == Unwind)
  1005.  
  1006. enum streamtype {
  1007.     Input, Output
  1008. };
  1009. struct stream {
  1010.     enum objtype type;
  1011.     enum streamtype stream_type;
  1012.     FILE *fp;
  1013. };
  1014.  
  1015. #define STREAMTYPE(obj)    (((struct stream *)obj)->type)
  1016. #define STREAMSTYPE(obj)   (((struct stream *)obj)->stream_type)
  1017. #define STREAMFP(obj)      (((struct stream *)obj)->fp)
  1018. #define STREAMP(obj)       (POINTERP(obj) && (STREAMTYPE(obj) == Stream))
  1019. #define INPUTSTREAMP(obj)  (STREAMP(obj) && (STREAMSTYPE(obj) == Input))
  1020. #define OUTPUTSTREAMP(obj) (STREAMP(obj) && (STREAMSTYPE(obj) == Output))
  1021.  
  1022. #define TYPE(obj)        (object_type (obj))
  1023. #define POINTERTYPE(obj) (PAIRTYPE(obj))
  1024. #define NULLP(obj)       (EMPTYLISTP(obj))
  1025. #define LISTP(obj)       (NULLP(obj) || PAIRP(obj))
  1026.  
  1027. /* <pcb> a wrapper around a system poiter. */
  1028.  
  1029. struct foreign_ptr {
  1030.     enum objtype type;
  1031.     void *ptr;
  1032. };
  1033.  
  1034. #define FOREIGNPTR(obj)      (((struct foreign_ptr *)obj)->ptr)
  1035. #define FOREIGNP(obj)        (POINTERP(obj) && (POINTERTYPE(obj) == ForeignPtr))
  1036. #define FOREIGNTYPE(obj)     (((struct foreign_ptr *)obj)->type)
  1037.  
  1038. struct environment {
  1039.     enum objtype type;
  1040.     struct frame *env;
  1041. };
  1042.  
  1043. #define ENVIRONMENT(obj)      (((struct environment *)obj)->env)
  1044. #define ENVIRONMENTP(obj)        (POINTERP(obj) && (POINTERTYPE(obj) == Environment))
  1045. #define ENVIRONMENTTYPE(obj)     (((struct environment *)obj)->type)
  1046.  
  1047. #endif /* not SMALL_OBJECTS */
  1048.  
  1049. /* globals */
  1050. extern jmp_buf error_return;
  1051.  
  1052. /* important objects */
  1053. extern Object true_object, false_object;
  1054. extern Object eof_object, unspecified_object, uninit_slot_object;
  1055. extern Object key_symbol, hash_rest_symbol, next_symbol;
  1056. extern Object quote_symbol;
  1057. extern Object getter_keyword, setter_keyword, else_keyword;
  1058. extern Object type_keyword, init_value_keyword, init_function_keyword;
  1059. extern Object init_keyword_keyword, required_init_keyword_keyword, allocation_keyword;
  1060. extern Object unwind_symbol, next_method_symbol, initialize_symbol;
  1061. extern Object equal_hash_symbol;
  1062. extern Object quasiquote_symbol, unquote_symbol, unquote_splicing_symbol;
  1063.  
  1064. /* builtin classes */
  1065. extern Object object_class;
  1066. extern Object boolean_class;
  1067. extern Object number_class, real_class, integer_class, ratio_class;
  1068. extern Object single_float_class, double_float_class;
  1069. extern Object collection_class, sequence_class, mutable_sequence_class;
  1070. extern Object mutable_collection_class;
  1071. extern Object list_class, empty_list_class, pair_class, string_class;
  1072. extern Object byte_string_class, vector_class, simple_object_vector_class;
  1073. extern Object explicit_key_collection_class, mutable_explicit_key_collection_class;
  1074. extern Object table_class, deque_class, array_class;
  1075. extern Object condition_class;
  1076. extern Object symbol_class, keyword_class;
  1077. extern Object character_class;
  1078. extern Object function_class, primitive_class, generic_function_class,
  1079.   method_class;
  1080. extern Object class_class, stream_class, table_entry_class, deque_entry_class;
  1081.  
  1082. /* from alloc.c */
  1083. extern Object allocate_object (size_t size);
  1084.  
  1085. /* convenience macro functions */
  1086. #define FIRST(obj)      (CAR(obj))
  1087. #define SECOND(obj)     (CAR(CDR(obj)))
  1088. #define THIRD(obj)      (CAR(CDR(CDR(obj))))
  1089. #define FOURTH(obj)     (CAR(CDR(CDR(CDR(obj)))))
  1090. #define FIFTH(obj)      (CAR(CDR(CDR(CDR(CDR(obj))))))
  1091.  
  1092. #define FIRSTVAL(vals)  (VALUESELS(vals)[0])
  1093. #define SECONDVAL(vals) (VALUESELS(vals)[1])
  1094. #define THIRDVAL(vals)  (VALUESELS(vals)[2])
  1095. #define FOURTHVAL(vals) (VALUESELS(vals)[3])
  1096. #define FIFTHVAL(vals)  (VALUESELS(vals)[4])
  1097.  
  1098. /* arbitrary constants */
  1099. #define MAX_STRING_SIZE 10240
  1100. #define MAX_SYMBOL_SIZE 1024
  1101. #define MAX_NUMBER_SIZE 255
  1102.  
  1103. enum objtype object_type (Object obj);
  1104.  
  1105. #endif
  1106.